package com.xja.dubbo.service.impl;

import com.xja.dubbo.entity.Easybuy_order;
import com.xja.dubbo.entity.Easybuy_order_detail;
import com.xja.dubbo.mapper.Easybuy_orderMapper;
import com.xja.dubbo.mapper.Easybuy_order_detailMapper;
import com.xja.dubbo.service.OrderService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author ycz
 * @create 2021-12-20-19:31
 */
@Component
@Service(interfaceClass = OrderService.class)
public class OrderServiceImpl implements OrderService {

    @Autowired
    private Easybuy_orderMapper easybuy_orderMapper;

    @Autowired
    private Easybuy_order_detailMapper easybuy_order_detailMapper;


    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public int addOrder(Easybuy_order order, List<Easybuy_order_detail> orderDetailList) throws Exception {
        //需要持久层做id回填
        easybuy_orderMapper.insertSelective(order);
        for (Easybuy_order_detail orderDetail : orderDetailList) {
            orderDetail.setOrderid(order.getId());
            easybuy_order_detailMapper.insertSelective(orderDetail);
        }
        return order.getId();
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void updateOrderPayStatus(Integer oid, String tradeId) throws Exception {
        Easybuy_order order = easybuy_orderMapper.selectByPrimaryKey(oid);
        order.setSerialnumber(tradeId);
        easybuy_orderMapper.updateByPrimaryKeySelective(order);
    }
}
